package Level01_two;

import java.util.ArrayList;
import java.util.Iterator;

public class Test {
    public static void main(String[] args) {
        Person person = new Person("小胡", 22, 1.80);
        Person person1 = new Person("小程", 21, 1.79);
        Person person2 = new Person("小向", 20, 1.78);
        Person person3 = new Person("李四", 19, 1.60);
        Person person4 = new Person("张三", 18, 1.81);
        ArrayList<Object> arrayList = new ArrayList<>();
        arrayList.add(person);
        arrayList.add(person1);
        arrayList.add(person2);
        arrayList.add(person3);
        arrayList.add(person4);
        Iterator<Object> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            //获取迭代元素
            Object next = iterator.next();
            //将元素转为Person类型，便于调用Person类中的对象
            Person person5 = (Person) next;
            person5.setAge(person5.getAge() + 2);
        }
        for (Object o : arrayList) {
            System.out.println(o);
        }
    }
}
